package com.future.direction.ui.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.future.direction.R;
import com.future.direction.common.util.UIUtil;
import com.future.direction.data.bean.StudyRecordsBean;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.adapter.StudyRecordsAdapter;
import com.future.direction.ui.widget.MyTitleBar;
import com.liaoinstan.springview.container.DefaultFooter;
import com.liaoinstan.springview.container.DefaultHeader;
import com.liaoinstan.springview.widget.SpringView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by zhp on 2019-11-08
 */
public class StudyRecordsActivity extends BaseActivity {
    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.recycle_study_records)
    RecyclerView recycleStudyRecords;
    @BindView(R.id.springView_study_records)
    SpringView springViewStudyRecords;
    private List<StudyRecordsBean> studyRecordsBeans;
    private StudyRecordsAdapter studyRecordsAdapter;


    @Override
    public int setLayout() {
        return R.layout.activity_study_records;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {
        initRecycle();
        return false;
    }

    @Override
    public void setListener() {
        backListener(titleBar);
        springViewStudyRecords.setListener(new SpringView.OnFreshListener() {
            @Override
            public void onRefresh() {

            }

            @Override
            public void onLoadmore() {

            }
        });
        studyRecordsAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(UIUtil.getContext(), CourseDetailsActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }

    private void initRecycle() {
        springViewStudyRecords.setHeader(new DefaultHeader(UIUtil.getContext()));
        springViewStudyRecords.setFooter(new DefaultFooter(UIUtil.getContext()));

        studyRecordsBeans = new ArrayList<>();
        studyRecordsBeans.add(new StudyRecordsBean());
        studyRecordsBeans.add(new StudyRecordsBean());
        studyRecordsBeans.add(new StudyRecordsBean());
        studyRecordsBeans.add(new StudyRecordsBean());
        studyRecordsBeans.add(new StudyRecordsBean());
        studyRecordsBeans.add(new StudyRecordsBean());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(UIUtil.getContext(), LinearLayoutManager.VERTICAL, false);
        recycleStudyRecords.setLayoutManager(linearLayoutManager);
        studyRecordsAdapter = new StudyRecordsAdapter(R.layout.item_study_records, studyRecordsBeans);
        recycleStudyRecords.setAdapter(studyRecordsAdapter);
    }
}
